<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="" prop="identifier">
        <el-input v-model="queryParams.identifier" placeholder="请输入标准号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入标准名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>

        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['business:book:export']">导出</el-button>
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['business:book:add']">
          新增</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="bookList" @selection-change="handleSelectionChange" border>
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="标准号" width="200" align="center" prop="identifier" />
      <el-table-column label="年代" width="100" align="center" prop="yearNumber" />
      <el-table-column label="标准名称" align="center" prop="name" />
      <el-table-column label="标准状态" width="100" align="center" prop="status" />
      <el-table-column label="标准类型" width="100" align="center" prop="bookclass" />
      <el-table-column label="发布日期" width="150" align="center" prop="releaseDate" />
      <el-table-column label="实施日期" width="150" align="center" prop="executeDate" />
      <el-table-column label="操作"  width="200" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['business:book:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['business:book:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改标准图书对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="书号" prop="no">
          <el-input v-model="form.no" placeholder="请输入书号" />
        </el-form-item>
        <el-form-item label="备案号" prop="record">
          <el-input v-model="form.record" placeholder="请输入备案号" />
        </el-form-item>
        <el-form-item label="标准号" prop="identifier">
          <el-input v-model="form.identifier" placeholder="请输入标准号" />
        </el-form-item>
        <el-form-item label="标准编号" prop="identifierNo">
          <el-input v-model="form.identifierNo" placeholder="请输入标准编号" />
        </el-form-item>
        <el-form-item label="标准年代号" prop="yearNumber">
          <el-input v-model="form.yearNumber" placeholder="请输入标准年代号" />
        </el-form-item>
        <el-form-item label="标准名称" prop="name">
          <el-input v-model="form.name" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="英文名称" prop="enName">
          <el-input v-model="form.enName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="标准类型" prop="bookclass">
          <el-input v-model="form.bookclass" placeholder="请输入标准类型" />
        </el-form-item>
        <el-form-item label="推荐性/强制性" prop="nature">
          <el-input v-model="form.nature" placeholder="请输入推荐性/强制性" />
        </el-form-item>
        <el-form-item label="标准代号" prop="preNo">
          <el-input v-model="form.preNo" placeholder="请输入标准代号" />
        </el-form-item>
        <el-form-item label="UDC号" prop="udcNo">
          <el-input v-model="form.udcNo" placeholder="请输入UDC号" />
        </el-form-item>
        <el-form-item label="定价" prop="price">
          <el-input v-model="form.price" placeholder="请输入定价" />
        </el-form-item>
        <el-form-item label="封面" prop="photo">
          <el-input v-model="form.photo" placeholder="请输入封面" />
        </el-form-item>
        <el-form-item label="有无PDF文件" prop="havepdf">
          <el-input v-model="form.havepdf" placeholder="请输入有无PDF文件" />
        </el-form-item>
        <el-form-item label="源文件" prop="file">
          <file-upload v-model="form.file" />
        </el-form-item>
        <el-form-item label="简介" prop="brief">
          <el-input v-model="form.brief" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="范围" prop="ownerdept">
          <el-input v-model="form.ownerdept" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="提出单位" prop="propOrg">
          <el-input v-model="form.propOrg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="发布单位" prop="releaseOrg">
          <el-input v-model="form.releaseOrg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="主管单位" prop="nuitOrg">
          <el-input v-model="form.nuitOrg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="归口单位" prop="underOrg">
          <el-input v-model="form.underOrg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="执行单位" prop="executeOrg">
          <el-input v-model="form.executeOrg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="出版单位" prop="publishOrg">
          <el-input v-model="form.publishOrg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="起草单位" prop="draftOrg">
          <el-input v-model="form.draftOrg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="起草人" prop="drafter">
          <el-input v-model="form.drafter" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="发布日期/修订日期" prop="releaseDate">
          <el-input v-model="form.releaseDate" placeholder="请输入发布日期/修订日期" />
        </el-form-item>
        <el-form-item label="公告日期" prop="declareDate">
          <el-input v-model="form.declareDate" placeholder="请输入公告日期" />
        </el-form-item>
        <el-form-item label="实施日期" prop="executeDate">
          <el-input v-model="form.executeDate" placeholder="请输入实施日期" />
        </el-form-item>
        <el-form-item label="作废日期" prop="invalidDate">
          <el-input v-model="form.invalidDate" placeholder="请输入作废日期" />
        </el-form-item>
        <el-form-item label="出版日期" prop="publishDate">
          <el-input v-model="form.publishDate" placeholder="请输入出版日期" />
        </el-form-item>
        <el-form-item label="电子版出版日期" prop="publishDatePdf">
          <el-input v-model="form.publishDatePdf" placeholder="请输入电子版出版日期" />
        </el-form-item>
        <el-form-item label="出版语言" prop="language">
          <el-input v-model="form.language" placeholder="请输入出版语言" />
        </el-form-item>
        <el-form-item label="代替标准" prop="replace">
          <el-input v-model="form.replace" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="被代替标准" prop="replaceBe">
          <el-input v-model="form.replaceBe" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="引用标准" prop="referstand">
          <el-input v-model="form.referstand" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="修订单信息" prop="modify">
          <el-input v-model="form.modify" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="采标信息：标号、名称、程度" prop="adopt">
          <el-input v-model="form.adopt" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="出版信息" prop="publishInfo">
          <el-input v-model="form.publishInfo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="读者对象" prop="reader">
          <el-input v-model="form.reader" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="ICS分类号" prop="bookIcs">
          <el-input v-model="form.bookIcs" placeholder="请输入ICS分类号" />
        </el-form-item>
        <el-form-item label="中标分类号" prop="bookCcs">
          <el-input v-model="form.bookCcs" placeholder="请输入中标分类号" />
        </el-form-item>
        <el-form-item label="来源" prop="from">
          <el-input v-model="form.from" placeholder="请输入来源" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listBook,
    getBook,
    delBook,
    addBook,
    updateBook
  } from "@/api/business/book";

  export default {
    name: "Book",
    data() {
      return {
        // 根路径
        baseURL: process.env.VUE_APP_BASE_API,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 标准图书表格数据
        bookList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          no: null,
          record: null,
          identifier: null,
          identifierNo: null,
          yearNumber: null,
          name: null,
          enName: null,
          status: null,
          bookclass: null,
          type: null,
          nature: null,
          preNo: null,
          udcNo: null,
          price: null,
          photo: null,
          havepdf: null,
          file: null,
          brief: null,
          ownerdept: null,
          propOrg: null,
          releaseOrg: null,
          nuitOrg: null,
          underOrg: null,
          executeOrg: null,
          publishOrg: null,
          draftOrg: null,
          drafter: null,
          releaseDate: null,
          declareDate: null,
          executeDate: null,
          invalidDate: null,
          publishDate: null,
          publishDatePdf: null,
          language: null,
          replace: null,
          replaceBe: null,
          referstand: null,
          modify: null,
          adopt: null,
          publishInfo: null,
          reader: null,
          bookIcs: null,
          bookCcs: null,
          from: null,
          remark: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          id: [{
            required: true,
            message: "$comment不能为空",
            trigger: "blur"
          }],
          name: [{
            required: true,
            message: "标准名称不能为空",
            trigger: "blur"
          }]
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询标准图书列表 */
      getList() {
        this.loading = true;
        listBook(this.queryParams).then(response => {
          this.bookList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          no: null,
          record: null,
          identifier: null,
          identifierNo: null,
          yearNumber: null,
          name: null,
          enName: null,
          status: "0",
          bookclass: null,
          type: null,
          nature: null,
          preNo: null,
          udcNo: null,
          price: null,
          photo: null,
          havepdf: null,
          file: null,
          brief: null,
          ownerdept: null,
          propOrg: null,
          releaseOrg: null,
          nuitOrg: null,
          underOrg: null,
          executeOrg: null,
          publishOrg: null,
          draftOrg: null,
          drafter: null,
          releaseDate: null,
          declareDate: null,
          executeDate: null,
          invalidDate: null,
          publishDate: null,
          publishDatePdf: null,
          language: null,
          replace: null,
          replaceBe: null,
          referstand: null,
          modify: null,
          adopt: null,
          publishInfo: null,
          reader: null,
          bookIcs: null,
          bookCcs: null,
          from: null,
          remark: null,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加标准图书";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getBook(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改标准图书";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateBook(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addBook(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除标准图书编号为"' + ids + '"的数据项？').then(function () {
          return delBook(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('business/book/export', {
          ...this.queryParams
        }, `book_${new Date().getTime()}.xlsx`)
      }
    }
  };

</script>
